import {createRouter, createWebHashHistory, createWebHistory, type Router} from "vue-router";

const router: Router = createRouter({
    history: createWebHashHistory(),
    routes: [
        {
            path: '/',
            name: 'root',
            redirect: '/main',
        },
        {
            path: '/main',
            component: () => import("@/views/MainPage.vue"),
            children: [
                {
                    path: '',
                    redirect: '/main/datasource',
                },
                {
                    path: 'datasource',
                    component: () => import("@/views/DataSourcesPage.vue"),
                },
                {

                    path: 'codegen',
                    component: () => import("@/views/CodeGenPage.vue"),
                },
            ]

        },
    ],
    /* 禁用鼠标侧键回退功能 */
    // scrollBehavior: () => {
    //     history.pushState(null, '', document.URL)
    // }
})
// 简化路由守卫调试
router.beforeEach((to, from, next) => {
    console.log(`Navigation to: ${to.path}`)
    // 临时禁用守卫逻辑
    next()

    /*
    正式代码：
    if (to.meta.requiresAuth) {
      if (store.state.user) next()
      else next('/login')
    } else {
      next()
    }
    */
})
export default router